<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>16-promise的then方法返回的promise的状态</title>
</head>
<body>
    <script>
        // let P1 = new Promise((resolve, reject) => {
        //     resolve("ok")
        // });
        // let result = P1.then(value=> {
        //     console.log(value)
        // }, reason => {
        //     console.wran("error")
        // });
        // console.log(result);
        /*情况一：throw抛出错误*/
        // let P2 = new Promise((resolve, reject) => {
        //     resolve("ok")
        // });
        // let result2 = P2.then(value=> {
        //     throw "出错了"
        // }, reason => {
        //     console.wran("error")
        // });
        // console.log(result2);
        /*情况二：返回非promise类型的值，状态为fulfilled*/
        // let P3 = new Promise((resolve, reject) => {
        //     resolve(555)
        // });
        // let result3 = P3.then(value=> {
        //     return 520;
        // }, reason => {
        //     console.wran("error")
        // });
        // console.log(result3);
        /*情况三：返回是一个promise类型的对象，新的对象有这个对象的状态决定*/
        let P3 = new Promise((resolve, reject) => {
            resolve(555)
        });
        let result3 = P3.then(value=> {
            return new Promise((resolve, reject) => {
                /*1.返回resolved状态时*/
                //resolve("success")
                /*2.返回rejected状态时*/
                reject("error");
            })
        }, reason => {
            console.wran("error")
        });
        console.log(result3);
    </script>
</body>
</html>